package com.cefa.edu.util;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.cefa.edu.pojo.JsonData;
import com.cefa.edu.pojo.Score;
import com.cefa.edu.pojo.User;
import org.apache.commons.collections.map.HashedMap;

import java.io.*;
import java.net.HttpURLConnection;
import java.net.URL;
import java.text.SimpleDateFormat;
import java.util.*;

/**
 * Created by qimwang on 9/22/17.
 */
public class JsonUtil {
    public static void main(String[] args) {
        //1、管理者、2老师 3学生和家长
//        List<Score> list = new ArrayList<>();
//        Score score = new Score();
//        score.setId(1);
//        score.setRoleType(1);
//
//        Score score2 = new Score();
//        score2.setId(2);
//        score2.setRoleType(1);
//
//        Score score3 = new Score();
//        score3.setId(2);
//        score3.setRoleType(1);
//        Score score33 = new Score();
//        score33.setId(2);
//        score33.setRoleType(4);
//
//        Score score34 = new Score();
//        score34.setId(5);
//        score34.setRoleType(4);
//
//        list.add(score33);
//        list.add(score2);
//        list.add(score34);
//        list.add(score3);
//        list.add(score);
//
//        List<Score> list1= new ArrayList<>();
//        Score score35 = new Score();
//        score35.setId(5);
//        score35.setRoleType(4);
//
//        Score score36 = new Score();
//        score36.setId(5);
//        score36.setRoleType(6);
//        list1.add(score);
//        list1.add(score35);
//        list1.add(score36);
//
//        List<Score> l= new ArrayList<>();
//        l.addAll(list);
//        l.addAll(list1);
//        for (Score s:l){
//            System.out.println(s.getId()+""+s.getRoleType());
//        }
//        System.out.println("----------------------------------------------");
//
////
////        Map<String,Score> map = new HashMap<>();
////        for (Score score4:list){
////            map.get(score4.getId()+""+score4.getRoleType());
////        }
//
//        Set<Score> personSet = new TreeSet<>((o1, o2) -> (o1.getId()+""+o1.getRoleType()).compareTo((o2.getId()+""+o2.getRoleType())));
//        personSet.addAll(list);
//
//         List<Score> ll=new ArrayList<>(personSet);
//        Collections.sort(
//                l,
//                (p1, p2) -> p1.getId().compareTo(p2.getId())
//        );
//         for (Score score5:ll){
//             System.out.println(score5.getId()+""+score5.getRoleType());
//         }

//        Calendar cal = Calendar.getInstance();//使用默认时区和语言环境获得一个日历。
//        cal.add(Calendar.DAY_OF_MONTH, -1);//取当前日期的前一天.
//        java.text.SimpleDateFormat format = new java.text.SimpleDateFormat("yyyy-MM-dd");
//        System.out.println(format.format(cal.getTime()));




//        String folder=System.getProperty("java.io.tmpdir");
//        File filename = new File(folder+"/suncity.txt");
//
//        String filein="你好！";
//        RandomAccessFile mm = null;
//        try {
//            mm.writeBytes(filein);
//
//        } catch (IOException e1) {
//            e1.printStackTrace();}
//        System.out.println("'{\"r\":\"7c02269b05c50c2d8213422ecf940009907292b38af519e7b4cea239d4829ad1\",\"s\":\"0cc0bb5dfe1e77d9b35fe3d64336a0f74332e4fd1317610f5997cb1110c5b028\",\"v\":28}'".length());
//        String str =HttpRequestUtil.sendPost("http://47.93.7.170:10010/tools/newwallet","","UTF-8");
//        User user=new User();
//        JSONObject jsStr = JSONObject.parseObject(str);
//        JSONObject jsStr2=(JSONObject) jsStr.get("msg");
//        String mnemonic=jsStr2.get("mnemonic").toString();
//        String path=jsStr2.get("path").toString();
//        String prikey=jsStr2.get("prikey").toString();
//        String address=jsStr2.get("address").toString();
//        String checksum=jsStr2.get("checksum").toString();
//        user.setMnemonic(mnemonic);
//        user.setPath(path);
//        user.setKeyData(prikey);
//        user.setAddress(address);
//        user.setChecksum(checksum);
////        System.out.println(prikey);
//        JSONObject jsonObject1= new JSONObject();
//        JSONObject jsonObject2= new JSONObject();
//        jsonObject2.put("json",jsonObject1.toJSONString());
//        jsonObject1.put("prikey","dddd");
//        jsonObject1.put("sha3data","ffff");
//        System.out.println(jsonObject2.toJSONString());

//        System.out.println("'{\"r\":\"7c02269b05c50c2d8213422ecf940009907292b38af519e7b4cea239d4829ad1\",\"s\":\"0cc0bb5dfe1e77d9b35fe3d64336a0f74332e4fd1317610f5997cb1110c5b028\",\"v\":28}' ".length());
        //-----保存
//
//
//        JSONObject j= new JSONObject();
//        j.put("stuAddress","0x68d53ecc07e2b58edaa4100e15d5982210aa2c21");
//        j.put("eduPrikey","fa41799fefda8d9218605b86658bc38c055f524444fd2b89e183d640a20e926b");
//        String ssss=HttpRequestUtil.sendPost("http://47.93.7.170:10010/contracts/deployfile",j.toJSONString(),"UTF-8");
//        System.out.println(ssss);















//        com.cefa.edu.pojo.User user= new com.cefa.edu.pojo.User();
//        String jsonData=HttpRequestUtil.sendPost("http://47.93.7.170:10010/tools/newwallet","{}","UTF-8");
//        System.out.println(jsonData);
//        String mnemonic=JSONObject.parseObject(JSONObject.parseObject(jsonData).get("msg").toString()).get("mnemonic").toString();
//        String path=JSONObject.parseObject(JSONObject.parseObject(jsonData).get("msg").toString()).get("path").toString();
//        String prikey=JSONObject.parseObject(JSONObject.parseObject(jsonData).get("msg").toString()).get("prikey").toString();
//        String address=JSONObject.parseObject(JSONObject.parseObject(jsonData).get("msg").toString()).get("address").toString();
//        String checksum=JSONObject.parseObject(JSONObject.parseObject(jsonData).get("msg").toString()).get("checksum").toString();
//        user.setKeyData(prikey);
//        user.setDerivePath(path);
//        user.setMnemonic(mnemonic);
//        user.setAddress(address);
//        user.setChecksum(checksum);
//        List<com.cefa.edu.pojo.User> userList=userMapper.getUserListBySchoolId(user.getSchoolId());
//        JSONObject jsonObject3= new JSONObject();
//        jsonObject3.put("stuAddress",address);
//        jsonObject3.put("eduPrikey",userList.get(0).getKeyData());
//        String studentData=HttpRequestUtil.sendPost("http://47.93.7.170:10010/contracts/deployfile",jsonObject3.toJSONString(),"UTF-8");
//        JSONObject json=JSONObject.parseObject(JSONObject.parseObject(studentData).get("msg").toString());
//        user.setFileAddress(json.get("fileAddress").toString());
//        user.setVerificationAddress(json.get("verificationAddress").toString());
        int correntYear = Calendar.getInstance().get(Calendar.YEAR);
        System.out.println(correntYear);

    }
}
